package com.example.expandablelistview

import android.content.Intent
import android.os.Bundle
import android.widget.ExpandableListView
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    private lateinit var expandableListView: ExpandableListView
    private val groups = arrayOf("BottomAppBar", "人力资源部", "销售部")
    private val childArr = arrayOf(arrayOf("Basic", "With Fab"),
                                 arrayOf("小红", "小白", "小明", "小狗"),
                                 arrayOf("张三", "李四", "王五", "赵六"))

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        title = "ExpandableListView二级下拉"
        initView()
    }

    private fun initView() {
        expandableListView = findViewById(R.id.expandListView)
        val expandableListViewAdapter = ExpandableListViewAdapter(groups, childArr, this)
        expandableListView.setAdapter(expandableListViewAdapter)

        expandableListView.setOnChildClickListener {parent, v, groupPosition, childPosition, id ->

            when(childArr[groupPosition][childPosition]) {
                "Basic" -> {
                    val intent = Intent(this, BtmAppBarBasic::class.java)
                    startActivity(intent)
                }
            }
            true
        }
    }
}

